﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using nERP.Model.Bas;
using nERP.Model;

namespace nERP.ViewModel.Bas.SettlementAccountVMs
{
    public partial class SettlementAccountListVM : BasePagedListVM<SettlementAccount_View, SettlementAccountSearcher>
    {
        
        protected override IEnumerable<IGridColumn<SettlementAccount_View>> InitGridHeader()
        {
            return new List<GridColumn<SettlementAccount_View>>{
                
                this.MakeGridHeader(x => x.SettlementAccount_Code).SetTitle(@Localizer["Page.编号"].Value),
                this.MakeGridHeader(x => x.SettlementAccount_Name).SetTitle(@Localizer["Page.名称"].Value),
                this.MakeGridHeader(x => x.SettlementAccount_BeginAmount).SetTitle(@Localizer["Page.期初金额"].Value),
                this.MakeGridHeader(x => x.SettlementAccount_NowAmount).SetTitle(@Localizer["Page.当前余额"].Value),
                this.MakeGridHeader(x => x.SettlementAccount_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),
                this.MakeGridHeader(x => x.SettlementAccount_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.SettlementAccount_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.SettlementAccount_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.SettlementAccount_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.SettlementAccount_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<SettlementAccount_View> GetSearchQuery()
        {
            var query = DC.Set<SettlementAccount>()
                
                .CheckContain(Searcher.Code, x=>x.Code)
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckEqual(Searcher.BeginAmount, x=>x.BeginAmount)
                .CheckEqual(Searcher.NowAmount, x=>x.NowAmount)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new SettlementAccount_View
                {
				    ID = x.ID,
                    
                    SettlementAccount_Code = x.Code,
                    SettlementAccount_Name = x.Name,
                    SettlementAccount_BeginAmount = x.BeginAmount,
                    SettlementAccount_NowAmount = x.NowAmount,
                    SettlementAccount_Remark = x.Remark,
                    SettlementAccount_CreateTime = x.CreateTime,
                    SettlementAccount_UpdateTime = x.UpdateTime,
                    SettlementAccount_CreateBy = x.CreateBy,
                    SettlementAccount_UpdateBy = x.UpdateBy,
                    SettlementAccount_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class SettlementAccount_View: SettlementAccount
    {
        
        public string SettlementAccount_Code { get; set; }
        public string SettlementAccount_Name { get; set; }
        public decimal? SettlementAccount_BeginAmount { get; set; }
        public decimal? SettlementAccount_NowAmount { get; set; }
        public string SettlementAccount_Remark { get; set; }
        public DateTime? SettlementAccount_CreateTime { get; set; }
        public DateTime? SettlementAccount_UpdateTime { get; set; }
        public string SettlementAccount_CreateBy { get; set; }
        public string SettlementAccount_UpdateBy { get; set; }
        public bool SettlementAccount_IsValid { get; set; }

    }

}